package com.example.myapplicationdemo01.slice;

import com.example.myapplicationdemo01.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class SecondAbilitySlice extends AbilitySlice {

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        this.setUIContent(ResourceTable.Layout_ability_second);
        // 在跳转后的slice的onStart方法中，从intent对象中获取数据
        if (intent != null) {
            // 因为intent.getParam()返回的是IntentParams, 所以先获取IntentParams然后再获取值
            IntentParams params = intent.getParams();
            String productId = (String) params.getParam("productId");
            // 获取到id=text1的文本组件
            Text text = (Text) findComponentById(ResourceTable.Id_text1);
            // 将获取到的商品ID设置到text文本组件
            text.setText(productId);
        }
    }
}
